﻿@model Backend.JYD.Model.Task.IntentEntryInfo
@using Backend.JYD.Model
@using Backend.JYD.Model.Cust
@using Backend.JYD.Web.Common
@using Backend.JYD.Business
@{
    ViewBag.Title = "意向录入";
    Layout = "~/Views/Shared/_LayoutWin.cshtml";

    var empInfo = ViewBag.LoginEmpInfo as EmpInfo;
    var custInfo = ViewBag.CustInfo as CustBase;
}

@using (Ajax.BeginForm("Create", new AjaxOptions() { OnSuccess = "aftersave" }))
{
<div class="ui_pop_body" style="width: 650px; height: 600px;float:left;">
    <div  style="width:600px;height:auto;">
        <fieldset>
            <legend>客户信息</legend>
            <ul class="edit-ul">
                 <li class="li01">
                    <span class="s01"></span>
                    <span class="s02">
                        
                    </span>
                </li>
                <li class="li01" id="liCustNo" style="display:none;">
                    <span class="s01">@Html.LabelFor(model => model.CustNo) : </span>
                    <span class="s02">
                        <input type="text" readonly="readonly" onfocus="this.blur();"  id="CustNo" disabled="disabled" name="CustNo" />
                    </span>
                </li>
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.CustName) : </span>
                    <span class="s02">@Html.TextBoxFor(model => model.CustName, new { id = "CustName" })
                         <input type="button" value="选" style="width:10px; padding-left:10px;" onclick="openCust()"/>
                        <input type="button" value="清除" id="btnclear" style="width:40px;display:none; padding-left:8px;" onclick="clearCust()"/>
                    </span>
                </li>
                <li class="li01" id="liPaperType">
                    <span class="s01">@Html.LabelFor(model => model.PaperType) : </span>
                    <span class="s02">@Html.DropDownListFor(model => model.PaperType, JydHtmlHelper.ConvertItemFormCodeInfo(true, CodeManager.PaperType, Model == null ? string.Empty : Model.PaperType), new {  id = "PaperType", style = "width:120px;" })</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.PaperType)</i>
                </li>
                 <li class="li01" id="liPaperNo">
                    <span class="s01">@Html.LabelFor(model => model.PaperNo) : </span>
                    <span class="s02">
                        @Html.TextBoxFor(model => model.PaperNo, new { id = "PaperNo" })
                        <input type="button" id="btnPaper" value="检查证件" onclick="checkPaper()" />
                    </span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.PaperNo)</i>
                </li>
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.Phone)   : </span>
                    <span class="s02">@Html.TextBoxFor(model => model.Phone, new { id = "Phone" })
                        <label for="ephone" style="display:none;"><input type="checkbox" value="1" id="ephone" name="ephone" onclick="editPhone()"/>修改客户电话</label>
                    </span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.Phone)</i>
                </li>
                 <li class="li01"  id="liChanelType">
                    <span class="s01">@Html.LabelFor(model => model.ChanelType) : </span>
                    <span class="s02">@Html.DropDownListFor(model => model.ChanelType, JydHtmlHelper.ConvertItemFormEnumType<CustManager.CustChanelType>(true), new { id = "ChanelType", style = "width:120px;" })</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.ChanelType)</i>
                </li>
            </ul>
        </fieldset>

        <fieldset>
            <legend>融资意向信息</legend>
            <ul class="edit-ul">
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.LoanMoney) : </span>
                    <span class="s02">@Html.EditorFor(model => model.LoanMoney)</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.LoanMoney)</i>
                </li>
               <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.Term) : </span>
                    <span class="s02">@Html.EditorFor(model => model.Term)</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.Term)</i>
                </li>
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.Rate) : </span>
                    <span class="s02">@Html.EditorFor(model => model.Rate)</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.Rate)</i>
                </li>
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.Purpose) : </span>
                    <span class="s02">@Html.EditorFor(model => model.Purpose)</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.Purpose)</i>
                </li>

                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.Guarantee) : </span>
                    <span class="s02">
                    @foreach (var item in JydHtmlHelper.ConvertItemFormCodeInfo(false, CodeManager.YesOrNo, Model == null ? string.Empty : (Model.Guarantee.HasValue && Model.Guarantee.Value ? "1" : "0")))
                    {
                        <label>@Html.RadioButton("Guarantee", item.Value, item.Selected, new { @id = "Guarantee" + item.Value })@item.Text</label>
                    }</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.Guarantee)</i>
                </li>
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.RepaymentType) : </span>
                    <span class="s02">@Html.DropDownListFor(model => model.Guarantee, JydHtmlHelper.ConvertItemFormCodeInfo(true, CodeManager.RepaymentType, Model == null ? string.Empty : (Model.RepaymentType.HasValue ? Model.RepaymentType.Value.ToString() : "0")))</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.RepaymentType)</i>
                </li>
               <li class="li02">
                    <span class="s01">@Html.LabelFor(model => model.Remark) : </span>
                    <span class="s02">@Html.TextAreaFor(model => model.Remark, new { @row = "2", @class = "input-text" })</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.Remark)</i>
                </li>
            </ul>
        </fieldset>            
    </div>
    <input type="submit" value="保存" onclick="return check(1);" />
    <input type="submit" value="保存并提交" onclick="return check(2);" />
    <input type="button" value="取消" onclick="closeWin()" />
    <input type="hidden" value="0" name="subtype" id="subtype"/>
</div>
    <script src="@Url.Content("~/skin/js/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/skin/js/check.js")" type="text/javascript"></script>
    if (!string.IsNullOrWhiteSpace(this.ViewBag.Msg))
    {
    <script type="text/javascript">        $(document).ready(function () { alert('@this.ViewBag.Msg'); });  </script>
    }
<script type="text/javascript">
    function aftersave(data) {
        if (data.code) {
            closeWinAndReload();
        }
        else {
            alert(data.msg);
        }
    }

    function check(type) {
        $('#subtype').val(type);
        if ($("#PaperNo").val() && !IdCardValidate($("#PaperNo").val())) {
            $("#PaperNo").focus();
            alert("请输入有效的身份证件");
            return false;
        }
//        if (!$("#Phone").val() || (!validateTelephone($("#Phone").val()) && !validateMobile($("#Phone").val()))) {
//            $("#Phone").focus();
//            alert("请输入有效的电话号码");
//            return false;
//        }
        return true;
        //创建新客户时，不用选择客户号，需要录入客户信息。
        //1，此时需要如果证件选择了身份证，需要验证身份证。
        //创建新客户时，或者允许修改电话。
        //2，检查电话，是否合法
        //3，根据电话，证件，验证是否存在有老客户，客户数据与新此数据符号，提示选择或者不选择。。
        //
        //检查意向数值是否合法。
    }

    function editPhone() {
        if ($('#ephone').attr('checked') == "checked") {
            $("#Phone").removeAttr("readOnly");
        }
        else {
            $("#Phone").attr("readOnly", "readOnly");
        }
    }
    function clearCust() {
        $("#CustNo").hide();

        $("#CustName").removeAttr("readOnly");
        $("#liPaperType").show();
        $("#liPaperNo").show();
        $("#Phone").removeAttr("readOnly");
        $("#liChanelType").show();
        $('#ephone').parent().hide();
        $('#btnclear').hide();
        $('#ephone').attr("checked", "checked");

        $("#CustNo").val('');
        $("#CustName").val('');
        $("#PaperType").val('');
        $("#PaperNo").val('');
        $("#Phone").val('');
        $("#ChanelType").val('');
    }
    function openCust() {
        windowShowModalDialog("/cust/frame", window, 950, 720);
    }
    function returnChoose(no, name, ptype, pno, cphone, channel) {
        $("#CustNo").show();
        $("#CustNo").val(no);
        $("#CustName").attr("readOnly", "readOnly");

        $("#CustName").val(name);
        $("#liPaperType").hide();
        $("#liPaperNo").hide();
        $("#liChanelType").hide();
        $("#PaperType").val(ptype);
        $("#PaperNo").val(pno);
        $("#Phone").val(cphone);
        $("#ChanelType").val(channel);
        $("#Phone").attr("readOnly", "readOnly");
        $('#ephone').parent().show();
        $('#ephone').removeAttr('checked');
        $('#btnPaper').hide();
        $('#btnclear').show();
        $('#ephone').parent().show();
       
    }
</script>
}
